<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@include file="/common/common.jsp" %>
    <link rel="stylesheet" href="${basePath}/css/layerPage.css${VERSION}"/>
    <link rel="stylesheet" href="${basePath}/assets/css/foundation-datepicker.css"/>
    
    
	<script type="text/javascript" src="${basePath}/assets/js/foundation-datepicker.js"></script>
	
    
</head>
<body>
<form id="form" name="form" class="form-horizontal" method="post" action="${basePath}/task/updateTask">
    <div class="panel-body">
        <div class="form-group">
            <label class="col-sm-3 control-label">任务名称：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="title" name="title" value="${tabCoreTask.title}"/>
                <input type="hidden" class="col-sm-5" id="taskId" name="taskId" value="${tabCoreTask.taskId}" />
                <input type="hidden" class="col-sm-5" id="taskPid" name="taskPid" value="${tabCoreTask.taskPid}" />
                <input type="hidden" class="col-sm-5" id="createUid" name="createUid" value="${tabCoreTask.createUid}" />
                <input type="hidden" class="col-sm-5" id="isDel" name="isDel" value="${tabCoreTask.isDel}" />
                <input type="hidden" class="col-sm-5" id="createTime" name="createTime" value="<fmt:formatDate value='${tabCoreTask.createTime}' type='both'/>" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">任务种类：</label>
            <div class="col-sm-9">
                <select id="taskCla" name="taskCla" class="selectpicker show-tick form-control">
                    <option value="66">简单任务</option>
                    <option value="22">工作日志</option>
                    <option value="33">蓝墙</option>
                    <option value="1">办公事宜</option>
                    <option value="2">文档编辑</option>
                    <option value="3">需求设计</option>
                    <option value="4">软件开发</option>
                    <option value="5">软件测试</option>
                    <option value="6">其它</option>
		          
        		</select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">任务类型：</label>
            <div class="col-sm-9">
                <select id="taskType" name="taskType" class="selectpicker show-tick form-control">
		          	<option value="1">紧急重要</option>
		          	<option value="2">紧急不重要</option>
		          	<option value="3">不紧急重要</option>
		          	<option value="4">不紧急不重要</option>
		            <option value="5">其它</option>
        		</select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">计划开始时间：</label>
            <div class="col-sm-9">
                <input type="text" class="date-icon" id="startTimePl" name="startTimePl" value="<fmt:formatDate value="${tabCoreTask.startTimePl}" pattern="yyyy-MM-dd"/>" readonly/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">计划结束时间：</label>
            <div class="col-sm-9">
                <input type="text" class="date-icon" id="endTimePl" name="endTimePl" value="<fmt:formatDate value="${tabCoreTask.endTimePl}" pattern="yyyy-MM-dd"/>"  readonly/>
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-9">
                <textarea id="description" name="description" rows="5" cols="30">${tabCoreTask.description}</textarea>
            </div>
        </div>
        <button id="submit" type="submit" class="btn btn-primary btn-submit">提交</button>
    </div>
</form>
<script type="text/javascript">
	
    jQuery(function ($) {
    	
    	
    	<%--$.ajax({--%>
            <%--type: "GET",--%>
            <%--url: "${basePath}/userTask/findAll?taskId=1",--%>
            <%--dataType: "json",--%>
            <%--beforeSend:function () {--%>
                <%----%>
            <%--},--%>
            <%--success: function (data) {--%>
                <%--if (data.status == "0") {--%>
                	<%--var y = JSON.stringify(data, null, 4);  --%>
                   	<%--alert(y);--%>
                <%--}else {--%>
                	<%--layer.msg(data.message);--%>
                <%--}--%>
            <%--},--%>
            <%--error: function(xhr, textStatus, errorThrown) {--%>
            	<%----%>
            <%--}--%>
        <%--});--%>
    	
    	
    	
    	
    	
    	jQuery.validator.methods.compareDate = function(value, element, param) {
            var startDate = jQuery(param).val();
            //alert(param+"--"+value);
            var date1 = new Date(Date.parse(startDate.replace("-", "/")));
            var date2 = new Date(Date.parse(value.replace("-", "/")));
            return date1 <= date2;
        };
    	
    	$('.date-icon').fdatepicker({
            format: 'yyyy-mm-dd'
        });
    	
    	
   		var taskC = ${tabCoreTask.taskCla}; //任务种类
   		switch(taskC){
            case 66:
                $('#taskCla option:eq(0)').attr('selected','selected');
                break;
            case 22:
                $('#taskCla option:eq(1)').attr('selected','selected');
                break;
            case 33:
                $('#taskCla option:eq(2)').attr('selected','selected');
                break;
   		       case 1:
   		    		$('#taskCla option:eq(3)').attr('selected','selected');
   		    	   	break;
   		       case 2:
   		    		$('#taskCla option:eq(4)').attr('selected','selected');
   		    	   	break;
   		       case 3:
   		    	   	$('#taskCla option:eq(5)').attr('selected','selected');
   		    	   	break;
   		       case 4:
   		    	   	$('#taskCla option:eq(6)').attr('selected','selected');
   		    	   	break;
   		       case 5:
   		    	  	$('#taskCla option:eq(7)').attr('selected','selected');
   		    	   	break;
   		       default:
   		    		$('#taskCla option:eq(8)').attr('selected','selected');
   		    		
   		 }
   		
   		var taskT = ${tabCoreTask.taskType}; //任务类型
   		switch(taskT){
   		       case 1:
   		    		$('#taskType option:eq(0)').attr('selected','selected');
   		    		//alert(taskT);
   		    	   	break;
   		       case 2:
   		    		$('#taskType option:eq(1)').attr('selected','selected');
   		    		//alert(taskT);
		    	   	break;
   		       case 3:
   		    		$('#taskType option:eq(2)').attr('selected','selected');
   		    		//alert(taskT);
		    	   	break;
   		       case 4:
   		    		$('#taskType option:eq(3)').attr('selected','selected');
   		    		//alert(taskT);
		    	   	break;
   		       default:
   		    		$('#taskType option:eq(4)').attr('selected','selected');
   		    		//alert(taskT);
		    	   
   		 }
        $("#startTimePl").change(function(){
            var startDate = $("#startTimePl").val();
            var endDate = $("#endTimePl").val();
            if($("#endId")!= null)  $("#endId").remove();
            if($("#startId")!= null) $("#startId").remove();
            if(startDate >endDate) {
                if($("#startId")!= null)
                    $("#startTimePl").after("<label id='startId'><font color='red'>计划开始时间不能大于计划结束时间</font></label>");
            }
        });
        $("#endTimePl").change(function(){
            var startDate = $("#startTimePl").val();
            var endDate = $("#endTimePl").val();
            if($("#startId")!= null)  $("#startId").remove();
            if ($("#endId") != null) $("#endId").remove();
            if(startDate >endDate) {
                if ($("#endId") != null)
                    $("#endTimePl").after("<label id='endId'><font color='red'>计划结束时间不能小于计划开始时间</font></label>");
            }
        });
    	
    	
        var $form = $("#form");
        var $loginName = $("#loginName");
        var $password = $("#password");
        var $confirmPassword = $("#confirmPassword");
        var $userName = $("#userName");
        var $submit = $("#submit");

        $form.validate({
        	errorClass: 'error-msg',
            rules: {
            	title:{
                    required:true
                    /*,remote: {
                        type: "post",
                        url: "${basePath}/task/checkTitle",
                        data: {
                        	title: function() {
                                return $("#title").val();
                            }
                        },
                        dataType: "json",
                        dataFilter: function(data, type) {
                            var json = eval('('+data+')');
                            if(json.status == '0'){
                                return true;
                            } else {
                                return false;
                            }
                        }
                    }*/
                },
                startTimePl: {
                    required: true
                },
                endTimePl: {
                    required: true,
//                    compareDate: "#startTimePl"
                },
                description:{
                	rangelength:[0,500]
                }

            },
            messages: {
            	title: {
                    required: "标题必填*",
                    remote: jQuery.format("标题已存在*")
                },
                startTimePl: "计划开始时间必填*",
                endTimePl:{
                	required:"计划结束时间必填*"
//                	compareDate:"计划结束日期必须大于计划开始日期!"
                },
                description:"任务说明长度不能超过100！*"
            },
            submitHandler: function (form) {
                $.ajax({
                    url: $form.attr("action"),
                    type: $form.attr("method"),
                    data: $form.serialize(),
                    
                    dataType: "json",
                    cache: false,
                    beforeSend: function () {
                        $submit.prop("disabled", true);
                    },
                    success: function (data) {
                    	//alert(data);
                        if (data.status == '0') {
                            $submit.prop("disabled", false);
                            layer.confirm('任务修改成功！是否关闭窗口？', {icon: 1}, function (index) {
                                parent.$("#grid-table").jqGrid().trigger("reloadGrid", [{page: 1}]);
                                parent.layer.close(parent.pageii);
                                return false
                            });
                        } else {
                            $submit.prop("disabled", false);
                            layer.alert(data, {
                                icon: 0,
                                skin: 'layui-layer-lan',
                                closeBtn: 0
                            });
                        }
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        $submit.prop("disabled", false);
                        layer.alert("系统未知错误", {
                            icon: 0,
                            skin: 'layui-layer-lan',
                            closeBtn: 0
                        });
                    }
                });
            }
        });


    });
</script>
</body>
</html>
